#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "linklist.h"
linklist linklist_init(void)
{
    return NULL;
}
linklist linklist_new(int data)
{
    linklist new = malloc(sizeof(listnode));
    if (new != NULL)
    {
        new->next = NULL;
        new->data = data;
    }
    else
        perror("产生新节点失败");
    return new;
}
linklist linkllist_add(linklist head, linklist new)
{
    if (head == NULL)
    {
        new->next=new;
        return new;
    }
    linklist tail;
    for (tail = head; tail->next != head; tail = tail->next);
    tail->next = new;
    new->next = head;
    return head;
}
void linklist_for_each(linklist head)
{
    if(head==NULL)
        return;
    linklist p;
    for (p = head;; p = p->next)
    {
        printf("%d\t", p->data);
        if(p->next==head)
            break;
    }
    printf("\n");
}
linklist linklist_del(linklist *phead, linklist p)
{
    linklist prv;
    for (prv = p->next; prv->next != p; prv = prv->next);
    prv->next = p->next;
    p->next = NULL;
    *phead = prv->next;
    return p;
}
linklist Josephus(linklist head)
{
    linklist p;
    while (head->next->next != head && head->next != head)
    {
        p=linklist_del(&head, head->next->next);
        free(p);
    }
    return head;
}